package com.kklsqm.langchain4j.config;

import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 功能:
 * 作者: 沙琪马
 * 日期: 2025/6/3 16:57
 */
@Configuration
public class LangChain4jConfig {

    @Bean
    public ChatMemoryProvider chatMemoryProvider() {
        return memoryId -> MessageWindowChatMemory.builder()
                .maxMessages(20)  // 保留最近20条消息作为记忆
                .id(memoryId)     // 使用传入的sessionId作为记忆ID
                .build();
    }
}